<template>
  <section>
    <el-table :data="leftList" size="mini" border stripe>
      <el-table-column label="左侧" prop="name"></el-table-column>
      <el-table-column v-for="(l,index) in labelList" :key="l.key" :label="l.name+'('+l.val+')'">
        <template slot-scope="scope">
          <span v-if="showVal(scope.row.val,labelList) === index">{{scope.row.val}}</span>
        </template>
      </el-table-column>
    </el-table>
    <el-table :data="rightList" size="mini" border stripe>
      <el-table-column label="右侧" prop="name"></el-table-column>
      <el-table-column v-for="(l,index) in labelList" :key="l.key" :label="l.name+'('+l.val+')'">
        <template slot-scope="scope">
          <span v-if="showVal(scope.row.val,labelList) === index">{{scope.row.val}}</span>
        </template>
      </el-table-column>
    </el-table>
  </section>
</template>

<script>
  import errHandler from '@/assets/errHandler.js'
  import {mapGetters, mapActions} from 'vuex'
  export default {
    name: "showDMS",
    props: ['OReporttm'],
    data() {
      return {
        labelList:null,
        zangfuList:[
          {name:'肺经'},
          {name:'大肠经'},
          {name:'胃经'},
          {name:'脾经'},
          {name:'心经'},
          {name:'小肠经'},
          {name:'膀胱经'},
          {name:'肾经'},
          {name:'心包经'},
          {name:'三焦经'},
          {name:'胆经'},
          {name:'肝经'},
        ],
        leftList:[],
        rightList:[],
        currDMS:null
      }
    },
    created(){
      console.log(this.OReporttm)
      let xsiyResult=this.OReporttm.xsiyResult
      let tmpArray=[]
      for(let k in xsiyResult){
        let tmp={key:k,val:parseInt(xsiyResult[k])}
        tmpArray.push(tmp)
      }
      this.currDMS=tmpArray
      //m2~6 实证虚症之类
      //m10~33 从左到右
      this.makeLabel(this.currDMS)
      this.makeTableDetail(this.currDMS)
    },
    watch:{
      // currDMS(nv,ov){
      //   console.log(nv)
      //   this.makeLabel(this.currDMS)
      // }
    },
    computed:{
      ...mapGetters(['department'])
    },
    methods: {
      ...mapActions({
        fetch: 'fetch'
      }),
      comparArray(a){
        let compare = function (x, y) {//比较函数
          if (x.val< y.val) {
            return -1;
          } else if (x.val > y.val) {
            return 1;
          } else {
            return 0;
          }
        }
        return a.sort(compare)
      },
      makeLabel(DMS){
        let index = DMS.findIndex(d=>d.key === 'm2')
        let tmp=DMS.slice(index,index+5)
        tmp=this.comparArray(tmp)
        tmp.forEach((t,i)=>{
          if(i===0){
            t.name='虚症'
          }else if(i===1){
            t.name='不足'
          }else if(i===2){
            t.name='正常'
          }else if(i===3){
            t.name='亢进'
          }else if(i===4){
            t.name='实证'
          }
        })
        this.labelList=tmp
      },
      makeTableDetail(DMS){
        let index = DMS.findIndex(d=>d.key === 'm10')
        let tmpLeft=DMS.slice(index,index+12)
        let tmpRight=DMS.slice(index+12,index+24)
        tmpLeft.forEach((l,i)=>{
          this.zangfuList.forEach((z,j)=>{
            if(i===j){
              l.name=z.name
            }
          })
        })
        tmpRight.forEach((l,i)=>{
          this.zangfuList.forEach((z,j)=>{
            if(i===j){
              l.name=z.name
            }
          })
        })
        this.leftList=tmpLeft
        this.rightList=tmpRight
      },
      showVal(val,vals){
        if(val <= vals[0].val) return 0
        if(val <= vals[1].val && val>vals[0].val) return 1
        if(val <= vals[3].val && val>vals[1].val) return 2
        if(val <= vals[4].val && val>vals[3].val) return 3
        return 4
      }
    }
  }
</script>

<style scoped>

</style>
